package com.tobby.camelinaction.client;

import java.util.concurrent.Future;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class CamelFutureGetTest extends CamelTestSupport {

	@Override
	protected RouteBuilder createRouteBuilder() {
		return new RouteBuilder() {

			@Override
			public void configure() throws Exception {
				// this is the route we want to send message to in an async manner.
				// usually the route is something that takes some time to do
				from("seda:quote").log("Starting to route ${body}").delay(5000).transform().constant("Camel Rocks")
						.log("Route is now done");
			}
		};
	}

	@Test
	public void testFutureGet() throws Exception {
		// now send the message to the endpoint in async manner
		// and get the Future handle back so we can later get the result
		log.info("Submitting task to Camel");
		Future<String> future = template.asyncRequestBody("seda:quote", "Hello Camel", String.class);
		log.info("Task submitted and we got a Future handle");

		// and get the answer (it will automaitc wait for the task to be complete)
		String answer = future.get();
		log.info("The answer is: " + answer);
	}

}
